home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group96a.txt
/
000074_icon-group-sender _Wed Apr 10 14:23:35 1996.msg
< prev
next >
Wrap
Internet Message Format
|
1996-09-05
|
3KB
Received: by cheltenham.cs.arizona.edu; Wed, 10 Apr 1996 16:20:25 MST
Date: Wed, 10 Apr 1996 14:23:35 -0700
From: kwalker@orville.premenos.com (Ken Walker)
Message-Id: <199604102123.OAA08553@varda.premenos.com>
To: icon-group@cs.arizona.edu
Subject: Re: How to think about Icon?
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Md5: JSmsXmNGzG1t3kCMAvGGZQ==
Errors-To: icon-group-errors@cs.arizona.edu
Status: O
> From: seebs@solutions.solon.com (Peter Seebach)
> Subject: How to think about Icon?
> ...
> What kind of conceptual model do you use for programming in Icon? How
> do you use it differently from "simple" procedural languages, like C
> or Perl?
I find it is easiest if I don't try to embrace the full potential of
generators and goal-directed evaluation all at once. The concept of
a "result sequence" can be very helpful. It lets you think independently
about all the potential results of a generator and how the results are used.
The concept becomes a little muddied when data structures used to generate
results change between results (for example, queens.icn in the Icon Program
Library modifies the chess board used to test for moves as it is generating
solutions), but in many cases the concept can be applied very cleanly.
The concept of a result sequence helps you write generative procedures by
allowing you to be concerned only with the sequence in which suspend
expressions are executed and not be concerned with why the procedure is
being resumed. On the other side of the coin, once you convince yourself
that an expression produces the sequence of values you want, you can
concentrate on how the sequence is used and forget about how it is
produced.
There are two basic paradigms for using generator: interation and goad-directed
evaluation. In interation, you are using all the values of a generator. For
example:
every write(!a)
writes all the values produced by !a.
In goal-directed evaluation, you are looking for a value from a generator
that meets a condition. For example, the expression
write(s ? (tab(find("name:")) & tab(upto(';'))))
locates the first position in s that contains "name:" and prints the
string from there upto to the next ";", if there is one.
Of course, things can get more complicated; you can also use this expression
in interation to produce a sequence of results. The following program
demonstrate's Marc Espie's warning about being careful when combining
generators and resuming them.
procedure main()
local s
s := "testing name:Jack; name:Jill;"
every write(s ? (tab(find("name:")) & tab(upto(';'))))
end
I expected it to print two results and it printed three:
name:Jack
name:Jack; name:Jill
name:Jill
I need to limit tab(upto(';')) to one result if I want to print
just the 1st and 3rd result.
Ken Walker, kwalker@premenos.com
Premenos Coporation, Concord, Ca. 94520